from odoo import models, fields, api

COMPUTER_LEVEL = [('level_one', '一级'), ('level_two', '二级'), ('level_three', '三级'), ('level_four', '四级'), ('level_four', '五级')]


class ResPartnerInheritForCommercial(models.Model):
    _inherit = 'res.partner'
    _description = '联系人'

    # 基础信息
    area_code = fields.Char(string='区号')
    telephone = fields.Char(string='手机')
    email = fields.Char(string='邮箱')

    # 地址信息
    user_id = fields.Many2one('res.users', default=lambda self: self.env.user)
    related_erp_tag = fields.Boolean(string='关联ERP')
    pe_merchant_id = fields.Many2one(string='商户', comodel_name='pe.merchant')
    pe_shop_id = fields.Many2one(string='门店', comodel_name='pe.merchant.shop')
    pe_shop_role_id = fields.Many2one(string='职位', comodel_name='pe.commercial.shop.role')
    duplicated_bank_account_partners_count = fields.Integer(default=1)
    pe_computer_level = fields.Selection(string='计算机等级', selection=COMPUTER_LEVEL)
    remark = fields.Char(string='备注')

    @api.model_create_single
    def create(self, values):
        erp_related = self.env.context.get('erp_related')
        if erp_related == 'related':
            values['related_erp_tag'] = True
        return super(ResPartnerInheritForCommercial, self).create(values)
